package com.example.dao.impl;

import com.example.dao.RefundRecordDao;
import com.example.entity.customerAdmin.RefundRecord;
import com.example.utils.BaseDao;

import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

public class RefundRecordDaoImpl implements RefundRecordDao {
    @Override
    public List<RefundRecord> selectAll (int page, int limit) {
        List<RefundRecord> refundRecordList=new ArrayList<> ();
        Object[] objects=new Object[2];
        objects[0]=page;
        objects[1]=limit;
        ResultSet select = BaseDao.select ("select * from refundrecord limit ?,?", objects);
        try {
            while (select.next ()){
                RefundRecord refundRecord=new RefundRecord ();
                refundRecord.setMoney (select.getInt ("money"));
                refundRecord.setMode (select.getString ("mode"));
                refundRecord.setDate (select.getString ("date"));
                refundRecord.setCreateTime (select.getString ("createTime"));
                refundRecord.setRelationOrder (select.getString ("relationOrder"));
                refundRecordList.add (refundRecord);
            }
        }catch (Exception e){
            e.printStackTrace ();
        }
        return refundRecordList;
    }

    @Override
    public int del (int id) {
        int i=-1;
        try {
            Object[] objects=new Object[1];
            objects[0]=id;
            i= BaseDao.modify ("delete from refundrecord where id=?",objects);
        }catch (Exception e){
            e.printStackTrace ();
        }
        return i;
    }

    @Override
    public RefundRecord selectId (int id) {
        RefundRecord refundRecord=new RefundRecord ();
        Object[] objects=new Object[1];
        objects[0]=id;
        ResultSet select = BaseDao.select ("select * from refundrecord where id=?", objects);
        try {
            while (select.next ()){
                refundRecord.setMoney (select.getInt ("money"));
                refundRecord.setMode (select.getString ("mode"));
                refundRecord.setDate (select.getString ("date"));
                refundRecord.setCreateTime (select.getString ("createTime"));
                refundRecord.setRelationOrder (select.getString ("relationOrder"));
                return refundRecord;
            }
        }catch (Exception e){
            e.printStackTrace ();
        }
        return null;
    }

    @Override
    public int getCount () {

        int i=-1;
        ResultSet select = BaseDao.select ("select count(1) getCount from refundrecord ",null);
        try {
            while (select.next ()){
                i=select.getInt ("getCount");
            }
        }catch (Exception e){
            e.printStackTrace ();
        }
        return i;
    }
}
